package cn.gjculture.shopping.api.service.impl;

import cn.gjculture.shopping.api.dao.LogisticsDao;
import cn.gjculture.shopping.api.entity.Logistics;
import cn.gjculture.shopping.api.entity.Order;
import cn.gjculture.shopping.api.service.LogisticsService;
import cn.gjculture.shopping.api.service.OrderService;
import cn.gjculture.shopping.api.service.VipOrderService;
import cn.gjculture.shopping.api.util.DateUtil;
import cn.gjculture.shopping.api.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;


@Service
public class LogisticsServiceImpl implements LogisticsService {

    @Autowired
    LogisticsDao logisticsDao;

    @Autowired
    OrderService orderService;

    @Autowired
    VipOrderService vipOrderService;



    @Override
    public int insert(Logistics logistics, String orderType) {
        Order order=new Order();
        order.setOrderId(logistics.getOrderId());
        order.setSendOutTime(DateUtil.getTimestamp());
        order.setStatus(9);
        if(StringUtils.isEmpty(orderType)){
            orderService.update(order);
        }else{
            vipOrderService.update(order);
        }
        logistics.setLogisticsId(UUIDUtil.getUUID());
        return logisticsDao.insert(logistics);

    }

    @Override
    public List<Logistics> queryByGoodsRecordId(String goodsRecordId) {
        return logisticsDao.queryByGoodsRecordId(goodsRecordId);
    }

    @Override
    public int delete(String logisticsId) {
        return logisticsDao.delete(logisticsId);
    }

}
